<template>
    <el-container class="home-container">
        <!-- 头部区域 -->
        <el-header>
            <div>
                <img src="../../assets/tubiao.png" width="61px" height="56px">
                <span>校园采购信息平台(管理员)</span>
            </div>
            <el-form>
                <el-form-item>
                    <el-button type="info" @click="logout">注销</el-button>
                </el-form-item>
            </el-form>
        </el-header>
        <!-- 页面主体区域 -->
        <el-container>
            <!-- 侧边栏 -->
            <el-aside :width="isCollapse ? '64px' : '200px'">
                <div class="toggle-button" @click="toggleCollapse">|||</div>
                <el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF" :unique-opened="true"
                         :collapse="isCollapse" :collapse-transition="false" router :default-active="activePath">
                    <!--一级菜单-->
                    <el-submenu index="1">
                        <template slot="title">
                            <!--图标-->
                            <i class="iconfont icon-users"></i>
                            <!--文本-->
                            <span>用户管理</span>
                        </template>
                        <el-menu-item index="submitters" @click="saveNavState('submitters')">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span>上报员列表</span>
                            </template>
                        </el-menu-item>
                        <el-menu-item index="buyers" @click="saveNavState('buyers')">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span>采购员列表</span>
                            </template>
                        </el-menu-item>
                        <el-menu-item index="manufacturers" @click="saveNavState('manufacturers')">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span>厂家列表</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                    <!--一级菜单-->
                    <el-submenu index="2">
                        <template slot="title">
                            <i class="iconfont icon-shangpin"></i>
                            <span>货物管理</span>
                        </template>
                        <el-menu-item index="goods" @click="saveNavState('goods')">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span>货物列表</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                    <!--一级菜单-->
                    <el-submenu index="3">
                        <template slot="title">
                            <i class="iconfont icon-danju"></i>
                            <span>订单管理</span>
                        </template>
                        <el-menu-item index="orders" @click="saveNavState('orders')">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span>订单列表</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <!--右侧主题内容-->
            <el-main>
                <!--路由占位符-->
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        data() {
            return {
                // 是否折叠
                isCollapse: false,
                //被激活的链接地址
                activePath: ''
            }
        },
        created() {
            this.activePath = window.sessionStorage.getItem('activePath')
        },
        methods: {
            logout() {
                window.sessionStorage.clear()
                this.$router.push('/login')
            },
            // 点击按钮，切换菜单的折叠与展开
            toggleCollapse() {
                this.isCollapse = !this.isCollapse
            },
            //保存链接的激活状态
            saveNavState(activePath) {
                window.sessionStorage.setItem('activePath', activePath)
                this.activePath = activePath
            }
        }
    }
</script>

<style scoped>
    .home-container {
        margin-top: 0px;
        height: 720px;
    }

    .el-header {
        background-color: #373d41;
        display: flex;
        justify-content: space-between;
        padding-left: 0;
        color: #fff;
        font-size: 20px;
    }

    .el-button {
        margin-top: 10px;
        align-items: center;
    }

    .el-header div {
        display: flex;
        align-items: center;
    }

    .el-header span {
        margin-left: 15px;
    }

    .el-aside {
        background-color: #333744;
    }

    .el-menu {
        border-right: none;
    }

    .el-main {
        background-color: #eaedf1;
    }

    .iconfont {
        margin-right: 10px;
    }

    .toggle-button {
        background-color: #4a5064;
        font-size: 10px;
        line-height: 24px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
    }
</style>
